package ilender.formatting;

import org.joda.time.format.*;

/**
 * Tools for formatting date and time.
 */
public final class DateTimeFormatting{
	/*Instantiation Guard*/private DateTimeFormatting(){}

	private static DateTimeFormatter jsonDateTime;
	/**Returns a formatter for JSON datetime.*/
	public static DateTimeFormatter forJsonDateTime(){
		if(null==jsonDateTime){
			synchronized(DateTimeFormatting.class){
				if(null==jsonDateTime){
					jsonDateTime=DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
				}
			}
		}
		return jsonDateTime;
	}

	private static DateTimeFormatter jsonDateMidnight;
	/**Returns a formatter for JSON date(without time).*/
	public static DateTimeFormatter forJsonDateMidnight(){
		if(null==jsonDateMidnight){
			synchronized(DateTimeFormatting.class){
				if(null==jsonDateMidnight){
					jsonDateMidnight=DateTimeFormat.forPattern("yyyy-MM-dd");
				}
			}
		}
		return jsonDateMidnight;
	}
}
